#可复制代码段--通过__doc__直接查看
#====读取数据==========================================
"""
#读取模拟参数
path=os.getcwd()
path=path+'/test/input.deck'
print(path)
para=al.parameter_simulation(dim=1,path=path)
pp=al.plot.parameter_plot(para)
num=30
data=sdf.read('piazza/%.4d.sdf'%num)

#meshgrid的用法
X, Y = np.meshgrid(data.grid_mid.data[0][xslice],data.grid_mid.data[1][yslice])
"""

import numpy as np
import analyse as al
import matplotlib.pyplot as plt

import matplotlib as mtplb

#===================
# plt.imshow(x, aspect='auto')


#========debug print=========
def dprint(*arg):
    if (al.Debug_flag == True):
        for i in arg:
            print(i, end='')
        print()


#可使用小函数
# def help_sdf_meshgrid()
#====one2two==========================================
def help_one2two(Z, X, Y=0):
    """
    Y需要自己调整范围

    Arguments:
        Z {[type]} -- [description]
        X {[type]} -- [description]
        Y {[type]} -- [description]
    """
    if ((Y == 0).all()):
        print("in func 'tool_one2two', no input for Y")
        return 0
    Z1 = np.zeros([len(Y), len(X)])
    X, Y = np.meshgrid(X, Y)
    [rows, cols] = X.shape
    for j in range(rows):
        for k in range(cols):
            Z1[j, k] = Z[k]
    return (Z1, X, Y)


#====绘制总colorbar==================================================
#在base_plot中也有
def share_colorbar(fig, tempax):
    #前面三个子图的总宽度 为 全部宽度的 0.9；剩下的0.1用来放置colorbar
    fig.subplots_adjust(right=0.9)
    #colorbar 左 下 宽 高
    l = 0.92
    b = 0.12
    w = 0.015
    h = 1 - 2 * b

    #对应 l,b,w,h；设置colorbar位置；
    rect = [l, b, w, h]
    cbar_ax = fig.add_axes(rect)
    cb = plt.colorbar(tempax, cax=cbar_ax)
    return cb